package com.cy.pj.notice.web.advice;

import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.notice.web.pojo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//此注解描述的类，为spring web模块定义的全局异常处理类
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

//    @ExceptionHandler(ServiceException.class)
//    public JsonResult doHandleServiceException(ServiceException e){
//        e.printStackTrace();//控制台打印异常
//        log.error("Exception{}",e.getMessage());//在日志输出异常
//        return new JsonResult(e);//
//    }

    @ExceptionHandler(ServiceException.class)
    public JsonResult doHandleRuntimeException(ServiceException e) {
//        e.printStackTrace();//控制台打印异常
        log.error("RuntimeException{}", e.getMessage());//在日志输出异常
        return new JsonResult(e);//
    }
}
